package com.sws.device.service.impl;

import java.util.List;
import com.sws.common.utils.DateUtils;
import com.sws.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sws.device.mapper.DevDeviceMapper;
import com.sws.device.domain.DevDevice;
import com.sws.device.service.IDevDeviceService;

/**
 * 设备信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-12
 */
@Service
public class DevDeviceServiceImpl implements IDevDeviceService 
{
    @Autowired
    private DevDeviceMapper devDeviceMapper;

    /**
     * 查询设备信息
     * 
     * @param id 设备信息主键
     * @return 设备信息
     */
    @Override
    public DevDevice selectDevDeviceById(Long id)
    {
        return devDeviceMapper.selectDevDeviceById(id);
    }

    /**
     * 查询设备信息列表
     * 
     * @param devDevice 设备信息
     * @return 设备信息
     */
    @Override
    public List<DevDevice> selectDevDeviceList(DevDevice devDevice)
    {
        return devDeviceMapper.selectDevDeviceList(devDevice);
    }

    /**
     * 新增设备信息
     * 
     * @param devDevice 设备信息
     * @return 结果
     */
    @Override
    public int insertDevDevice(DevDevice devDevice)
    {
        devDevice.setCreateTime(DateUtils.getNowDate());
        return devDeviceMapper.insertDevDevice(devDevice);
    }

    /**
     * 修改设备信息
     * 
     * @param devDevice 设备信息
     * @return 结果
     */
    @Override
    public int updateDevDevice(DevDevice devDevice)
    {
        devDevice.setUpdateTime(DateUtils.getNowDate());
        devDevice.setUpdateTime(DateUtils.getNowDate());
        devDevice.setUpdateBy(SecurityUtils.getUsername());
        return devDeviceMapper.updateDevDevice(devDevice);
    }

    /**
     * 批量删除设备信息
     * 
     * @param ids 需要删除的设备信息主键
     * @return 结果
     */
    @Override
    public int deleteDevDeviceByIds(Long[] ids)
    {
        return devDeviceMapper.logicalDeleteDevDeviceByIds(ids);
    }

    /**
     * 删除设备信息信息
     * 
     * @param id 设备信息主键
     * @return 结果
     */
    @Override
    public int deleteDevDeviceById(Long id)
    {
        return devDeviceMapper.logicalDeleteDevDeviceById(id);
    }
    
    /**
     * 查询被逻辑删除的设备信息
     * 
     * @return 设备信息集合
     */
    @Override
    public List<DevDevice> selectLogicalDeletedDevDevices()
    {
        return devDeviceMapper.selectLogicalDeletedDevDevices();
    }
    
    /**
     * 物理删除被逻辑删除的设备信息
     * 
     * @return 结果
     */
    @Override
    public int physicalDeleteLogicalDeletedDevices()
    {
        List<DevDevice> devices = devDeviceMapper.selectLogicalDeletedDevDevices();
        if (devices != null && !devices.isEmpty())
        {
            Long[] ids = devices.stream().map(DevDevice::getId).toArray(Long[]::new);
            return devDeviceMapper.deleteDevDeviceByIds(ids);
        }
        return 0;
    }
    
    /**
     * 根据序列号查询设备信息
     * 
     * @param sn 设备序列号
     * @return 设备信息
     */
    @Override
    public DevDevice selectDevDeviceBySn(String sn)
    {
        return devDeviceMapper.selectDevDeviceBySn(sn);
    }
}
